<?php

require_once CORE_DIRECTORY.OS_PATH_SEPARATOR.'basePlugin.php';
require_once CORE_DIRECTORY.OS_PATH_SEPARATOR.'file.php';

/*
 * BaseUpload is the parent class for upload plugins
 * It handles multiple files and allow saving of theses files
 */
class BaseUpload extends BasePlugin
{
	private $_uploadedFiles;
	protected $data;

	// Make a new instance of a plugin and get $_REQUEST['data'] to allow processing of external part of some plugins
	// like ftp, shell, zenity
	public function __construct()
	{
		$this->_uploadedFiles = array();
		
		$this->data = null;
		if(isset($_REQUEST['data']))
		{
			$this->data = $_REQUEST['data'];
		}
	}
	
	// Get the XHTML form of this plugin is it makes sens
	public function XHTMLForm()
	{
		return '';
	}
	
	// Save each handled files
	public function process()
	{
		foreach($this->_uploadedFiles as $f)
		{
			$f->save();
		}
		return $this->_uploadedFiles;
	}
	
	// Add a file to the handled file list
	public function addUploadedFile($file)
	{
		if($file->exists())
		{
			$this->_uploadedFiles[] = $file;
		}
	}
	
	// Return the handled file list
	public function getUploadedFiles()
	{
		return $this->_uploadedFiles;
	}
	
	// Specific metadata plugin to inactivate for this specific instance
	public function unactivateMetadataPlugins()
	{
		return array();
	}
	
	// Action to do after upload success
	public function success()
	{
		redirect('index.php');
	}
	
	// Action to do after upload error
	public function error()
	{
		redirect('index.php');
	}
}
